#include<stdio.h>
#include "process.h"
#include<time.h>
#include <stdlib.h>



typedef void(*flush_t) (double total,double current); //函数指针

const int base = 20;//单词下载量的基础值
double total = 2048.0;//需要下载的量
double once = 0.1;//速度

void download(flush_t f)
{
    double current = 0.0;
    while(current < total)
    {
        //模拟下载行为
        int r = rand()%base+1;
        double speed = r * once;
        current += speed;
        if(current > total) current = total;
        usleep(10000);

        //更新本次下载量
        f(total,current);
    }
    printf("\n");
}

int main()
{
    srand(time(NULL));
    download(FlushProcess);
    download(FlushProcess);
    download(FlushProcess);
    download(FlushProcess);

    return 0;
}